﻿/**
 * Session监听模块
 */
function SessionWatcher() {
    //通知对象
    this.watchSesssionId = null;
    this.lastAccessTime = null;
    this.sessionTimeout = 20 * 60 * 1000;
    this.SessionTimeoutHandler = null;
}

SessionWatcher.prototype = {
    /**
     * 启动Session监听
     */
    watch: function () {
        var self = this;
        self.lastAccessTime = new Date();
        self.watchSesssionId = setInterval(function () {
            var now = new Date();
            if (now - self.lastAccessTime > self.sessionTimeout) {
                if (self.SessionTimeoutHandler) {
                    self.SessionTimeoutHandler();
                }
            }
        }, 1000);
    },

    /**
     * 停止Session监听
     */
    stop: function () {
        if (this.watchSesssionId) {
            clearInterval(this.watchSesssionId);
        }
    }
}
